from sqlalchemy import BigInteger, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.core.models.enums.user import LangCode

from .base import TimedBaseModel


class User(TimedBaseModel):
    __tablename__ = "user"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True)
    username: Mapped[str] = mapped_column(String(255))
    calendars = relationship(
        "UserCalendar", back_populates="user", cascade="all,delete"
    )
    subscription = relationship(
        "Subscription", back_populates="user", cascade="all,delete"
    )
    bills = relationship("Bill", back_populates="user")
    lang_code: Mapped[LangCode] = mapped_column(server_default="ru")

    def __repr__(self):
        return f"<Пользователь №{self.id} {self.telegram_id}>"

    def __str__(self):
        return self.__repr__()
